﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class Control_ProDotuoi_Detail
    Inherits System.Web.UI.UserControl
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Not Request.QueryString("Id").ToString.Equals("0") Then
                hidID.Value = Request.QueryString("Id")
                ShowData()
            End If
        End If
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p As BanHang = (From q In data.BanHangs Where q.Id = hidID.Value Select q).SingleOrDefault
            If Not p Is Nothing Then
                lblOrderid.Text = IIf(IsNothing(p.BanHangId) = True, "", p.BanHangId)
                lblStoreid.Text = IIf(IsNothing(p.StoreId) = True, "", p.StoreId)
                lblCustomername.Text = IIf(IsNothing(p.CustomerName) = True, "", p.CustomerName)
                lblAddress.Text = IIf(IsNothing(p.Address) = True, "", p.Address)
                lblEmail.Text = IIf(IsNothing(p.Email) = True, "", p.Email)
                lblPhone.Text = IIf(IsNothing(p.Phone) = True, "", p.Phone)
                lblOrderdate.Text = IIf(IsNothing(p.BanHangDate) = True, "", CType(p.BanHangDate, DateTime).ToString("dd/MM/yyyy"))
                lblCreator.Text = IIf(IsNothing(p.Creator) = True, "", p.Creator)
                lblCreated.Text = IIf(IsNothing(p.Created) = True, "", CType(p.Created, DateTime).ToString("dd/MM/yyyy HH:mm"))

                lblModifier.Text = IIf(IsNothing(p.Modifier) = True, "", p.Modifier)
                If Not p.Modifier Is Nothing Then
                    lblModified.Text = CType(p.Modified, DateTime).ToString("dd/MM/yyyy HH:mm")
                End If
                If Not p.GrossAmount Is Nothing Then
                    lblGrossAmount.Text = CType(p.GrossAmount, Double).ToString("##,###")
                End If

                Dim d = (From q In data.BanHangDetails Where q.BanHangId = p.Id Select New With {q.BanHangId, q.ProductCode, q.Product.Title, q.Number, .GrossAmount = q.GrossAmount}).ToList
                Dim strKey_Name() As String = {"BanHangId"}
                With grdShow
                    .DataKeyNames = strKey_Name
                    .DataSource = d
                    .DataBind()
                End With

            End If
        End Using
    End Sub


#End Region

    Protected Sub grdShow_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdShow.RowDataBound
        If e.Row.RowIndex >= 0 Then
            Dim lbItem As Label = e.Row.FindControl("lbItem")
            lbItem.Text = e.Row.RowIndex + 1

            ' Dim promotionApply = grdShow.DataKeys(e.Row.RowIndex)("PromotionApply")
        End If
    End Sub

    Protected Sub Print_Click(sender As Object, e As System.EventArgs) Handles Print.Click
        Response.Redirect("InHoaDon.aspx?Id=" & hidID.Value)
    End Sub
End Class
